
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { MutationRes } from 'src/modules/shared/vo/mutation.res';
import { RoleEntity } from 'src/modules/system/role/entities/role.entity';

@Injectable()
export class RoleService {
  constructor(
    @InjectRepository(RoleEntity)
    private readonly roleRepository:Repository<RoleEntity>
  ) {}

  async createRole(name: string): Promise<MutationRes> {
    const role = this.roleRepository.create({name});
    await this.roleRepository.save(role);
    return {
      code: 0,
      message: '创建成功',
    }
  }

  async roleList(): Promise<RoleEntity[]> {
    return await this.roleRepository.find();
  }
}
